from dao.course_dao import (get_courses_by_teacher_name, get_course_classes_by_coruse_id)
from dao.grade_dao import (get_grade_by_class_id)


def get_courses_by_teachername(name):
    res = []
    courses = get_courses_by_teacher_name(name)
    for index0, course in enumerate(courses):
        course_id = course['code']
        a_course = {
            'id': str(index0 + 1),
            'index': str(index0 + 1),
            'course_name': course['name'],
            'course_id': course_id
        }
        course_classes = get_course_classes_by_coruse_id(course.get('code'))
        grades = []
        for index1, course_class in enumerate(course_classes):
            grade = get_grade_by_class_id(course_class['class_id'])
            if not grade:
                continue
            a_grade = {
                'index': str(index0 + 1) + '-'+ str(index1 + 1),
                'class_name': grade['c_name'],
                'class_id': grade['c_id']
            }
            grades.append(a_grade)
        a_course["have_this_course_class"] = grades
        res.append(a_course)
    return res




